package com.cardmanage.controller;

import com.cardmanage.common.Result;
import com.cardmanage.pojo.Card;
import com.cardmanage.pojo.NewCard;
import com.cardmanage.service.CardService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin(origins = "http://localhost:8080")
@RequiredArgsConstructor
@RestController
@RequestMapping("/card")
public class CardController {
    private final CardService cardService;

    /**
     * 查询单个名片
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public Result<Card> GetOne(@PathVariable Integer id) {
        System.out.println("查询页面");
        return cardService.GetOne(id);
    }

    /**
     * 查询所有名片
     * @return
     */
    @GetMapping("/get/all")
    public Result<List> GetAll(){
        return cardService.GetAll();
    }

    /**
     * 新增名片
     * @param newCard
     * @return
     */
    @PostMapping("/create")
    public Result CreateOne(@RequestBody NewCard newCard) {
        System.out.println("接收请求");
        return cardService.create(newCard);
    }

    /**
     * 编辑名片
     * @param card
     * @return
     */
    @PostMapping("/edit")
    public Result EditOne(@RequestBody Card card) {
        return cardService.editOne(card);
    }

    /**
     * 删除名片
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public Result Delete(@PathVariable Integer id) {
        return cardService.delete(id);
    }

}
